{extend name="main" /}

{block name="body"}
{include file="breadcrumb" /}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="btn-box">
                <a href="{:url('add')}" class="layui-btn layui-btn-sm xn_open">添加单页</a>
            </div>
            <form action="{:url('sort')}" method="post">
                <table class="layui-table" style="margin-top: 0;">
                    <tr>
                        <th style="width: 45px;">排序</th>
                        <th>ID</th>
                        <th>标题</th>
                        <th>Banner</th>
                        <th width="140">操作</th>
                    </tr>

                    <tbody>
                    {foreach name="list" item="vo"}
                    <tr>
                        <td><input type="text" name="{$vo.id}" placeholder="排序" autocomplete="off" class="layui-input" value="{$vo.sort}" style="width: 45px;height:24px;line-height:24px;color: #999;"></td>
                        <td>{$vo.id}</td>
                        <td>{$vo._name}</td>
                        <td>
                            {if condition="!empty($vo['image'])"}<img src="{$vo.image}" class="xn_img" style="height: 40px">{/if}
                        </td>
                        <td>
                            <a href="{:url('edit',array('id'=>$vo['id']))}" title="{$vo.title}" class="layui-btn layui-btn-sm xn_open">
                                修改
                            </a>
                            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm dropdown-btn" data-id="{$vo.id}">
                                <span>更多</span>
                                <i class="layui-icon layui-icon-down layui-font-12"></i>
                            </button>
                        </td>
                    </tr>
                    {/foreach}
                    <tr>
                        <td colspan="5">
                            <button type="submit" class="layui-btn layui-btn-warm layui-btn-sm">排序</button>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    /*操作 下菜单*/
    layui.use(function(){
        // 渲染
        var dropdown = layui.dropdown;
        dropdown.render({
            elem: '.dropdown-btn', // 绑定元素选择器，此处指向 class 可同时绑定多个元素
            data: [{
                title: '添加子页面',
                type: 'add'
            },{
                title: '删除',
                type: 'delete'
            }],
            click: function(data){
                var elem = $(this.elem)
                var id = elem.data('id'); //被选中的ID

                if(data.type === 'add'){
                    layer.open({
                        type: 2
                        ,title: data.title
                        ,content: "{:url('add')}?pid="+id
                        ,area: ['900px', '740px']
                    });
                } else if ( data.type === 'delete' ) {
                    //询问框
                    var tip = "确定要删除此条信息吗？"
                    layer.confirm(tip, {
                        title:"操作提示",
                        icon: 7,
                        btn: ['确定','取消'] //按钮
                    }, function(){
                        var url = "{:url('delete')}";
                        $.get(url,{id:id},function(data){
                            if( data.code === 1 ) {
                                location.reload();
                            } else {
                                xn_alert(data.msg);
                            }
                        },'json')
                    }, function(){

                    });
                }
            }
        });
    });
</script>
{/block}